package priv.yiyuan.example.design.wrapper;

import java.util.ArrayList;
import java.util.List;

/**
 * 复合图形
 * <p>
 * 组合模式-组合节点
 *
 * @author YiYuan
 * @data 2025/9/1
 * @apoNote
 */
public class CompositeGraphic implements Graphic {

    private List<Graphic> children = new ArrayList<>();

    public void add(Graphic graphic) {
        children.add(graphic);
    }

    @Override
    public void draw() {
        for (Graphic child : children) {
            child.draw();
        }
    }

    @Override
    public Graphic clone() {
        CompositeGraphic clone = new CompositeGraphic();
        for (Graphic child : children) {
            clone.add(child);
        }

        return clone;
    }
}
